<template>
	<div>
		<div class="header">
			<el-row style="padding: 5px 0 0 0;">
				<el-col :span="2">
					<el-button size="mini" @click="dialogVisibles=true,title='添加标题',insert()"
						style="width: 90px;height: 40px;background-color: #00A0FF;color: #fff;">
						获取商品</el-button>
				</el-col>
			</el-row>
		</div>
		<el-table :header-cell-style="{'text-align':'center'}" :cell-style="{ textAlign: 'center' }"
			:data="cmsCommodity.records" stripe style="width: 100% width: 80%;margin: auto">
			<el-table-column property="id" label="编号">
			</el-table-column>
			<el-table-column property="name" label="商品名称">
			</el-table-column>
			<el-table-column property="price" label="单价">
			</el-table-column>
			<el-table-column label="类型">
				<template slot-scope="scope">
					<el-select v-model="scope.row.levelId" clearable placeholder="全部" style="width: 200px;">
						<el-option v-for="item in cmsCommodityLevel" :key="item.id" :value="item.id" :label="item.name"
							style="width: 200px;">
						</el-option>
					</el-select>
				</template>
			</el-table-column>
			<el-table-column label="操作">
				<el-row slot-scope="scope">
					<el-button
						@click="dialogVisibles=true,title='修改标题',id=scope.row.id,getOne(scope.row.id),titles=scope.row.title,tagId=scope.row.tagId">修改标题</el-button>
				</el-row>
			</el-table-column>
		</el-table>
		<div>
			<el-row>
				<el-col :span="20">
					<div class="block">
						<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
							:current-page="1" :page-sizes="[10, 20, 50,100]" :page-size="10"
							layout="total, sizes, prev, pager, next, jumper" :total="cmsCommodity.total">
						</el-pagination>
					</div>
				</el-col>
			</el-row>
		</div>
	</div>
</template>

<script>
	import '@/assets/css/index.css'
	import qs from 'qs'
	export default {
		name: "qu",
		data() {
			return {
				advertisersList: [],
				resourceCategory: [],
				aName: '',
				aId: '',
				role: '',
				categoryIds: '',
				dialogVisible: false,
				description: '',
				title: '',
				resource: [],
				roleDescriptions: {},
				ams: [],
				cmsCommodity: [],
				size: 10,
				current: 1,
				cmsCommodityLevel: []
			}
		},
		created() {
			this.lists();
		},
		methods: {
			insert() {
				this.$axios.post('cmsCommodity/list').then((res) => {
					this.lists();
					console.log(res)
				})
			},
			lists() {
				let than = this
				this.$axios.post('cmsCommodity/getList', qs.stringify({
					size: than.size,
					current: than.current
				})).then((res) => {
					than.cmsCommodity = res.data;
					console.log(than.cmsCommodity)
				})
				this.$axios.post('cmsCommodityLevel/list').then((res) => {
					than.cmsCommodityLevel = res.data
				})
			},
			handleSizeChange(val) {
				let that = this
				this.$axios.post('cmsCommodity/getList', qs.stringify({
					size: val,
					current: 1,
				})).then((res) => {
					that.advertisersList = res.data;
					console.log(that.advertisersList)
				})
			},
			handleCurrentChange(val) {
				let that = this;
				this.$axios.post('cmsCommodity/getList', qs.stringify({
					size: that.advertisersList.size,
					current: val,
				})).then((res) => {
					that.advertisersList = res.data;
				})
			},
			goToExternalUrl() {
				// 使用 window.location.href 跳转到外部 URL  
				window.location.href =
					'https://open.oceanengine.com/audit/oauth.html?app_id=1797546706202640&state=your_custom_params&scope=%5B300000000%2C2%2C4%2C5%2C9%2C130%2C110%2C112%2C14%2C120%2C122%2C123%2C124%2C100000005%5D&material_auth=1&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&rid=98ym2wdjps7'; // 外部 URL  
			},
			selectLike() {
				let that = this
				this.$axios.post('amsTitle/getPageList', qs.stringify({
					size: 5,
					current: 1,
					title: that.aName
				})).then((res) => {
					that.advertisersList = res.data;
					console.log(that.advertisersList)
				})
			},
		}
	}
</script>

<style>
	.header {
		width: auto;
		height: 50px;
		border: 1px solid #ddd;
		margin: 15px auto;
		border-radius: 3px 3px;
		position: relative;
	}
</style>